package es.deusto.ingenieria.aike.time;

import java.util.List;

import es.deusto.ingenieria.aike.csp.formulation.Variable;

public class NodeConsistency implements ConstraintPropagation
{
	private List<Variable<Integer>> variables;
	private Environment environment;
	
	public NodeConsistency(List<Variable<Integer>> variables,Environment environment)
	{
		this.variables = variables;
		this.environment = environment;
	}
	
	public boolean makeConsistent() 
	{
		Integer multiplier = environment.getMultiplier();
		Integer constant = environment.getConstant();
		
		for (int i = 0; i<variables.size();i++)
		{
			Boolean modified = false;
			Variable<Integer> variable = variables.get(i);
			List<Integer> domain = variable.getDomain();
			if (domain.contains(constant))
			{
				domain.remove(constant);
				modified = true;
			}
			if (domain.contains(multiplier))
			{
				domain.remove(multiplier);
				modified = true;
			}
			if ((variable.getName().equals("2"))||(variable.getName().equals("6")))
			{
				for (int j = 6; j < 10; j++)
				{
					if(domain.contains(j))
					{
						domain.remove(domain.indexOf(j));
						modified = true;
					}
				}
			}
			if (modified)
			{
				variable.setDomain(domain);
			}
		}
		Boolean variableNull = false;
		int index = 0;
		while (index < variables.size())
		{
			variableNull = (variables.get(index).getDomain().isEmpty()?true:false);
			index++;
		}
		return variableNull;
	}

	public List<Variable<Integer>> getVariables() {
		return variables;
	}

	public void setVariables(List<Variable<Integer>> variables) {
		this.variables = variables;
	}
	
	

}
